<template>
	<u-popup :show="showPrivacy" round="10">
		<button @tap="handleOpenPrivacyContract">查看隐私协议</button>
		<button id="agree-btn" open-type="agreePrivacyAuthorization"
			@agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
	</u-popup>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import XNavigationBar from '@/components/navigationBar/xNavigationBar.vue'
	import XImage from '@/components/image/xImage.vue'


	export default {
		components: {
			XNavigationBar,
			XImage
		},
		computed: {
			...mapState(['userInfo'])
		},

		onLoad() {

		},
		data() {
			return {
				showPrivacy: false
			}
		},

		methods: {
			check() {
				wx.getPrivacySetting({
					success: res => {
						console.log(
								res
								) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
						if (res.needAuthorization) {
							// 需要弹出隐私协议
							this.showPrivacy = true
							// this.setData({
							// 	showPrivacy: true
							// })
						} else {
							this.$emit("authed")
							// 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用已声明过的隐私接口
							// wx.getUserProfile()
							// wx.chooseMedia()
							// wx.getClipboardData()
							// wx.startRecord()
						}
					},
					fail: () => {},
					complete: () => {}
				})
			},
			handleAgreePrivacyAuthorization() {
				// 用户同意隐私协议事件回调
				// 用户点击了同意，之后所有已声明过的隐私接口和组件都可以调用了
				// wx.getUserProfile()
				// wx.chooseMedia()
				// wx.getClipboardData()
				// wx.startRecord()
				this.$emit("authed")
			},
			handleOpenPrivacyContract() {
				// 打开隐私协议页面
				wx.openPrivacyContract({
					success: () => {}, // 打开成功
					fail: () => {}, // 打开失败
					complete: () => {}
				})
			}
		}

	}
</script>

<style lang="scss" scoped>

</style>